Int stands for integer I guess.
Consider the following program:
I first I declared c as a char which makes sense to me (I want to store a character). I wanted to try to declare it as an int, since it can then store EOF. This also works.Code:#include <stdio.h> int main(void) { char text[90]; int i, c, n; // getchar printf("String: "); n = 0; while((c = getchar()) != '\n') //c is an integer { text[n] = c; n++; } text[n] = '\0'; printf("Print out the string: %s\n", text); }
I thought int variables contained numbers and not letters.
1) Anyone want to clarify this for me?
2) Shouldn't the int variable store the ASCI number for the particular character?
3) How does getchar() know that it should jump one step to the right in the while loop? It looks like it should stand at the same character all the time, but it doesn't fortunatuly.
4) Also the statement c = getchar() is an allocation inside the while loop I guess? Is this recommended? It looks kind of odd to me.
Thanks a lot!